﻿using System;
using VisionarySystems.Library;

namespace VisionarySystems.TimeRegi.Registry
{
    public class RegistryLayer
    {
        #region private const

        private const string KEY_PATH = "Software\\Visionary Systems\\TimeRegi";

        #endregion

        #region private members

        static string m_MySQLDataSource = string.Empty;
        static TimeSpan m_BreakPerDay = TimeSpan.MinValue ;
	    private static DateTime m_OverTimeStartDate = DateTime.MinValue;
	    private static TimeSpan m_RegisterNoMoveTime = TimeSpan.MinValue;

	    #endregion

        #region Public methods

        public static string DataSource
        {
            get
            {
                if (m_MySQLDataSource == string.Empty)
                {
                    const string DATA_SOURCE_KEY = "Data source";
                    m_MySQLDataSource = VisionarySystems.Library.RegistryUtils.ReadRegistryValue(KEY_PATH, DATA_SOURCE_KEY, "SQLExpress");
                }
                return m_MySQLDataSource;
            }
        }

        public static TimeSpan BreakPerDay
        {
            get
            {
                if (m_BreakPerDay == TimeSpan.MinValue)
                {
                    const string BREAK_PER_DAY_KEY = "Break per day";
                    int minutesPerDay = Convert.ToInt32(RegistryUtils.ReadRegistryValue(KEY_PATH, BREAK_PER_DAY_KEY, "30"));
                    m_BreakPerDay = new TimeSpan(0, minutesPerDay, 0);
                }
                return m_BreakPerDay;
            }
        }

		public static DateTime OverTimeStartDate
		{
			get
			{
				if (m_OverTimeStartDate == DateTime.MinValue)
				{
					const string OverTimeStartDateKey = "Overtime start date";
					m_OverTimeStartDate = Convert.ToDateTime(Library.RegistryUtils.ReadRegistryValue(KEY_PATH, OverTimeStartDateKey, "01-11-2012"));
				}
				return m_OverTimeStartDate;
			}
		}

	    public static TimeSpan RegisterNoMoveTime
	    {
			get
			{
				if (m_RegisterNoMoveTime == TimeSpan.MinValue)
				{
					const string REGISTER_NO_MOVE_TIME_KEY = "Register no move time";
					int minutesPerDay = Convert.ToInt32(RegistryUtils.ReadRegistryValue(KEY_PATH, REGISTER_NO_MOVE_TIME_KEY, "240"));
					m_RegisterNoMoveTime = new TimeSpan(0, minutesPerDay, 0);
				}
				return m_RegisterNoMoveTime;
			}
	    }

	    #endregion

    }
}
